<?php

namespace Biz\module\Behaviors\Stock;

use Biz\cache\ActivitysStock;
use Biz\model\activity\LimitTimeRobbing as mLimitTimeRobbing;
use Biz\model\activity\LimitTimeRobbingSku as mLimitTimeRobbingSku;
use Biz\model\GoodsStockLog;

class LimitTimeStock extends StockBehaviorsAbstruct
{

    const TYPE_LOG = GoodsStockLog::TYPE_LIMIT_TIME_ROBBING;


    public static function setStocksCache($goods_ids)
    {
        $NoHappendedInfos = mLimitTimeRobbing::selectNoHappenedInfos($goods_ids);

        foreach ($NoHappendedInfos as $key => $happendedInfo) {

            list($robbing_id, $goods_id) = explode("_", $key);

            ActivitysStock::setMutiStocks($robbing_id, $goods_id, array_column($happendedInfo, "promo_stock", "sku_id"));
        }

    }


    public static function updateDbStock($current_stock)
    {
        mLimitTimeRobbingSku::setMutiStock($current_stock);
    }

    public static function DecrStocksCounter($buyNums)
    {
        return ActivitysStock::DecrStocksRobbingCounter($buyNums);

    }

    public static function IncrStocksCounter($buyNums)
    {

        return ActivitysStock::IncrStocksRobbingCounter($buyNums);
    }
}